#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int V = 0;
    cin >> V;
    cerr << "V=" << V << endl;
    int n = 0;
    cin >> n;
    cerr << "n=" << n << endl;
    vector<int> v(n + 1, 0);
    for (int i = 1;i < n + 1;i++)
    {
        cin >> v[i];
        cerr << v[i] << " ";
    }
    cerr << endl;
    vector<vector<int>> dp(n + 1, vector<int>(V + 1, 0));
    for (int i = 1;i < n + 1;i++)
    {
        for (int j = 1;j < V + 1;j++)
        {
            if (j - v[i] >= 0)
            {
                //cerr<<"j="<<j<<",i="<<i<<",v[i]="<<v[i]<<"|";
                dp[i][j] = max(v[i] + dp[i - 1][j - v[i]], dp[i - 1][j]);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];

            }
        }
        //cerr<<endl;
    }
    // for(int i=0;i<n+1;i++)
    // {
    //     for(int j=0;j<V+1;j++)
    //     {
    //         cerr<<dp[i][j]<<" ";
    //     }
    //     cerr<<endl;
    // }
    cout << V - dp[n][V] << endl;
    cerr << V - dp[n][V] << endl;
    return 0;
}